<template>
  <div class="app-container" v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="140px">
      <el-divider content-position="left">增值税发票</el-divider>
      <el-form-item label="增值税发票类型" prop="invoiceTypeId">
        <el-checkbox-group v-model="form.invoiceTypeId">
          <el-checkbox v-for="item in invoiceTypeList"  :label="item.invoiceTypeId" :key="item.invoiceTypeId">{{item.invoiceTypeName}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>

      <el-form-item label="行业类型" prop="industryType">
        <el-radio-group v-model="form.industryType">
          <el-radio :label="1">常规行业</el-radio>
          <el-radio :label="2">特殊商业</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>

    <div class="dialog-footer">
      <el-button type="primary" @click="submitForm">提 交</el-button>
      <el-button @click="handleCancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { getOtherQuery, otherEdit} from "@/api/system/merchant";
import {listInvoiceType} from "@/api/system/InvoiceType";

export default {
  name: "otherInfo",
  props:{
    organizationId:{
      type:String,
    },
  },
  data() {
    return{
      loading:false,
      form:{
        industryType:null,
        invoiceTypeId:[],
        organizationId:null,
      },
      invoiceTypeList:[],
      // 表单校验
      rules: {
        invoiceTypeId: [
          { required: true, message: "请选择增值税发票类型", trigger: "change" }
        ],
        industryType: [
          { required: true, message: "请选择行业类型", trigger: "change" }
        ]
      }
    }
  },
  mounted() {
    listInvoiceType().then(res=>{
      this.invoiceTypeList = res.rows
    })
  },
  methods:{

    getDetail(){
      this.loading = true
      getOtherQuery(this.organizationId).then(res=>{
        this.loading = false
        if (res.data){
          let other = res.data
          other.invoiceTypeId = other.invoiceTypeId.split(",")
          this.form = other

        }
      }).catch(()=>{
        this.loading = false
      })
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true
          let other = this.form
          other.invoiceTypeId = other.invoiceTypeId.join(",")
          other.organizationId = this.organizationId
          otherEdit(other).then(response => {
            this.loading = false
            this.$modal.msgSuccess("保存成功")
            this.handleCancel(true)
            this.active++
          }).catch(()=>{
            this.loading = false
          })
        }
      })

    },

    handleCancel(val){
      this.$emit("cancel",val)
    },
  },
  watch:{
    organizationId:{
      handler(val){
        if (val){
          this.getDetail()
        }
      },
      immediate:true
    },
  }
}
</script>
<style scoped lang="scss">
::v-deep .el-col{
  .el-form-item{
    width: 100%;
    .el-date-editor{
      width: 100%;
    }
  }
}
.line{
  text-align: center;
}

::v-deep .el-radio-group{
  .el-radio{
    height: 36px;
    line-height: 35px;
  }
}
</style>
